﻿using System.Collections.Generic;
using System.Data;

//MONTI
namespace ConfExpert.Forms.ImportWizards
{
    public partial class Monti_Tip1 : XITopCekiListesi
    {
        int YuklemeId;
        public Monti_Tip1(int YuklemeId):
            base(YuklemeId)
        {
            InitializeComponent();

            this.YuklemeId = YuklemeId;
            Init("Monti Tip1 Çeki Listesi",true);
            this.FileDone += this_FileDone;
            //this.SplitterWidthPercentage = 30;
        }

        void this_FileDone(DataSet ds, string FileName)
        {
            foreach (DataTable dt in ds.Tables)
            {
                DataRowCollection rows = dt.Rows;
                DataColumnCollection cols = dt.Columns;

                Dictionary<string, int> indexes = new Dictionary<string, int>();
                for (int colIndex = 0; colIndex < dt.Columns.Count; colIndex++)
                {
                    DataRow dr0 = dt.Rows[0];
                    switch (dr0[colIndex].ToString())
                    {
                        case "Packing List No.": indexes.Add("PackingListNo", colIndex); break;
                        case "Art": indexes.Add("Kalite", colIndex); break;
                        case "Fin": indexes.Add("Fin", colIndex); break;
                        case "Des": indexes.Add("DesenNo", colIndex); break;
                        case "Col": indexes.Add("Color", colIndex); break;
                        case "Roll": indexes.Add("VendorRollId", colIndex); break;
                        case "Roll Lenght Mt.": indexes.Add("Qty", colIndex); break;
                        case "Roll Width  Cm.": indexes.Add("WidthUsable", colIndex); break;
                        //case "Our OC No.": indexes.Add("OrderConfirmNo", colIndex); break;
                        //case "Your PO Ref.":
                        //    if (!indexes.ContainsKey("PO"))
                        //        indexes.Add("PO", colIndex);
                        //    break;
                        //case "Your PO Date": indexes.Add("PODate", colIndex); break;
                        //case "Customer Art.Ref.": indexes.Add("CustomerCode", colIndex); break;
                        //case "Invoice No.": indexes.Add("InvoiceNo", colIndex); break;
                        //case "Invoice Date": indexes.Add("InvoiceDate", colIndex); break;
                        //case "Package No.": indexes.Add("KoliNo", colIndex); break;
                        //case "HS Code": indexes.Add("GumrukRefNo", colIndex); break;
                    }
                }

                for (int i = 1; i < dt.Rows.Count; i++)
                {
                    DataRow dr = rows[i];
                    string article = dr[indexes["Kalite"]].ToString().PadLeft(3, '0') +
                        (dr[indexes["Fin"]].ToString() != "0" ? "-" + dr[indexes["Fin"]].ToString().PadLeft(2, '0') : string.Empty) +
                        "-" + dr[indexes["DesenNo"]].ToString().PadLeft(4, '0') +
                        "/" + dr[indexes["Color"]].ToString().PadLeft(3, '0');

                    if (Article.Select("Article='" + article + "'").Length == 0)
                    {
                        DataRow drArticle = Article.NewRow();
                        drArticle["Article"] = article;
                        Article.Rows.Add(drArticle);
                    }
                    DataRow drRoll = Roll.NewRow();
                    drRoll["Article"] = article;
                    drRoll["VendorRollId"] = dr[indexes["VendorRollId"]];
                    drRoll["Qty"] = dr[indexes["Qty"]];
                    drRoll["WidthUsable"] = dr[indexes["WidthUsable"]];
                    //drRoll["PackingListNo"] = dr[indexes["PackingListNo"]];
                    //drRoll["PO"] = dr[indexes["PO"]];
                    //drRoll["PODate"] = dr[indexes["PODate"]];                
                    //drRoll["InvoiceNo"] = dr[indexes["InvoiceNo"]];
                    //drRoll["InvoiceDate"] = dr[indexes["InvoiceDate"]];
                    //drRoll["KoliNo"] = dr[indexes["KoliNo"]];
                    //drRoll["GumrukRefNo"] = dr[indexes["GumrukRefNo"]];

                    Roll.Rows.Add(drRoll);
                }
            }
        }
        
    }
}


